from HTMLTestRunner import HTMLTestRunner
import unittest
import time
import os.path

# loader 返回一个suite对象，可以直接执行
loader = unittest.defaultTestLoader.discover('./test_package',pattern='demo*')

# runner
# 准备要写入的文件
path = os.path.abspath('report')
# strftime('%Y%m%d%H%M%S') time转化为str格式
filename = time.strftime('%Y%m%d%H%M%S') + '-demo.html'
filename_path = os.path.join(path,filename)

# 打开文件，执行runner
with open(filename_path,'wb') as f:
    runner = HTMLTestRunner(
        title= '测试报告标题',
        description='测试报告详细描述',
        tester='fine',
        stream= f,
        verbosity=2
    )
    runner.run(loader)

